package com.panda.game.xls.screen;

import com.panda.game.xls.action.AddRowAction;
import com.panda.game.xls.action.SheetTypeDataAction;
import com.panda.game.xls.component.MyJButton;
import com.panda.game.xls.component.MyJTable;
import com.panda.game.xls.config.SheetTypeData;
import com.panda.game.xls.config.SheetTypeDataConfig;
import com.panda.game.xls.constant.ScreenConstant;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.List;

public class TabPage2 extends TabPageFather implements TabInterface {

    private static MyJButton saveBtn;

    private static MyJButton addBtn;

    public static MyJTable table;

    public static DefaultTableModel tableModel;

    public TabPage2() {
        super();
        setLayout(new GridLayout(3, 1));
        setDefaultSeting();
        setTabContent();
    }

    @Override
    public void setTabContent() {
        List<SheetTypeData> sheetTypeDataList = SheetTypeDataConfig.getSheetTypeDataList();

        String[] columnNames = {"分组类型", "sheet名称", "排序"};
        tableModel = new DefaultTableModel(new Object[][]{}, columnNames);
        table = new MyJTable(tableModel);

        for (int i = 0; i < sheetTypeDataList.size(); i++) {
            SheetTypeData sheetTypeData = sheetTypeDataList.get(i);
            tableModel.addRow(new Object[]{sheetTypeData.getType(), sheetTypeData.getName(), sheetTypeData.getSort()});
        }
        JScrollPane pane = new JScrollPane(table);
        add(pane);

        saveBtn = new MyJButton(50, 30);
        Action save = new SheetTypeDataAction();
        saveBtn.setAction(save);
        saveBtn.setText("保存");
        add(saveBtn);

        addBtn = new MyJButton(50, 30);
        Action add = new AddRowAction(ScreenConstant.ADD_TYPE_SHEETTYPEDATA);
        addBtn.setAction(add);
        addBtn.setText("增加行");
        add(addBtn);

    }

}
